#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 5, M = 6e3 + 5;
long long n, m, mm, u[M], v[M], w[M], T, dis[N], uu, vv, ww;
bool njzy(int s)
{
    memset(dis, 0x3f, sizeof(dis));
    dis[s] = 0;
    bool flag = false;
    for (int i = 1; i <= n; i++) {
        flag = false;
        for (int j = 1; j <= mm; ++j) {
            if (dis[u[j]] == 0x3f3f3f3f3f3f3f3f) // 判断是否能到达当前点（WA Sub1 #2）
                continue;
            if (dis[u[j]] + w[j] < dis[v[j]]) {
                dis[v[j]] = dis[u[j]] + w[j];
                flag = true;
            }
        }
        if (!flag)
            break;
        // cnt >= n的时候也有可能flag当时没有松弛，所以要判断flag
    }
    return flag;
}
int main()
{
    cin >> T;
    while (T--) {
        cin >> n >> m;
        mm = 0;
        for (int i = 1; i <= m; ++i) {
            cin >> uu >> vv >> ww;
            mm++;
            u[mm] = uu, v[mm] = vv, w[mm] = ww;
            if (ww >= 0) {
                mm++;
                u[mm] = vv, v[mm] = uu, w[mm] = ww;
            }
        }
        if (njzy(1))
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }
    return 0;
}